//
//  FriendOneTableViewCell.m
//  YiXiProject
//
//  Created by iMac on 2019/7/25.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "FriendOneTableViewCell.h"

#import "FriendCollectionViewCell.h"  // cell

@implementation FriendOneTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectV.delegate = self;
        _collectV.dataSource = self;
        _collectV.showsHorizontalScrollIndicator = NO;
        _collectV.backgroundColor = WhiteColor;
        [self.contentView addSubview:_collectV];
        _collectV.sd_layout.leftSpaceToView(self.contentView, 0).topSpaceToView(self.contentView, 1).rightSpaceToView(self.contentView, 0).bottomSpaceToView(self.contentView, 1);
        
        
        //注册重复使用的cell
        [_collectV registerClass:[FriendCollectionViewCell class] forCellWithReuseIdentifier:@"collId"];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _collList.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FriendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collId" forIndexPath:indexPath];
    
    [cell installDataDic:_collList[indexPath.row]];
    
    return cell;
}


#pragma mark - UICollectionViewDelegateFlowLayout
//设置cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize size = CGSizeMake(self.bounds.size.width/4, self.bounds.size.width/3);
    return size;
}

//设置cell与边缘的间隔
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UIEdgeInsets inset = UIEdgeInsetsMake(0, 0, 0, 0);
    return inset;
}

//最小行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0.1;
}

//最小列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld",indexPath.row);
    
    if([_delegate respondsToSelector:@selector(clickFriendCollectiomItemTag:)])
    {
        [_delegate clickFriendCollectiomItemTag:indexPath.row];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
